from page.login_page import LoginPage
from base.util import BoxDriver,BasePage
import unittest
from parameterized import parameterized
from time import sleep

class LoginTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = BoxDriver()
        cls.loginPage = LoginPage(cls.driver)

    @classmethod
    def tearDownClass(cls):
        cls.driver.close()

    @parameterized.expand(BasePage.get_excel(r'selenium\ranzhi\data\data.xlsx','success'))
    def test_success(self,username,password):
        '''登陆成功测试用例'''
        try:
            self.loginPage.login(username,password)
            # 断言
            realname = self.loginPage.get_realname()
            self.assertEqual(realname,username,'用例执行失败！')
        except AssertionError as e:
            raise AssertionError('断言错误！')
        except Exception as e:
            # 手工抛出异常
            raise Exception('发生错误！')
        finally:
            self.loginPage.exit()

    @parameterized.expand(BasePage.get_excel(r'selenium\ranzhi\data\data.xlsx','fail'))
    def test_fail(self,username,password):
        '''登陆失败测试用例'''
        try:
            self.loginPage.login(username,password)
            # 断言
            msg = self.loginPage.get_msg()
            self.assertEqual(msg,'登录失败，请检查您的成员名或密码是否填写正确。','用例执行失败')
        except AssertionError as e:
            raise AssertionError('断言错误！')
        except Exception as e:
            # 手工抛出异常
            raise Exception('发生错误！')
        finally:
            self.loginPage.confirm()

if __name__ == "__main__":
    unittest.main()